# coding=utf-8
from django.db import models

class Image(models.Model):
	url = models.CharField(max_length=1000)
	description = models.CharField(max_length=2000)
	def __unicode__(self):
		return self.url

class ImageWelcome(Image):
	pass
	

class Question(models.Model):
	question = models.CharField(max_length=1000)
	answer = models.CharField(max_length=5000)
	def __unicode__(self):
		if len(self.question) < 100:
			return self.question
		else:
			return self.question[:97] + '...'

class Group(models.Model):
	name = models.CharField(max_length=40)
	def __unicode__(self):
		return self.name
	def hasItem(self):
		#nSubGroups = len(SubGroup.objects.filter(group=self))
		#return nSubGroups > 0
		return True #TODO

class SubGroup(models.Model):
	group = models.ForeignKey(Group)
	name = models.CharField(max_length=40)
	def __unicode__(self):
		return self.name

class Item(Image):
	subGroup = models.ForeignKey(SubGroup)
	name = models.CharField(max_length=200)
	price = models.FloatField(default=10)
	def getPriceString(self):
		return 'A partir de ' + `self.price` + '€'
	def __unicode__(self):
		return self.name


